﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ane.JobApps.Models;

namespace ane.JobApps.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        private ProfileRepository mProfileRepository = new ProfileRepository();
        private JobAppRepository mJobAppRepository = new JobAppRepository();
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ane.Job Applications ";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Add()
        {
            ViewData["User"] = mProfileRepository.GetCurrentProfile("ane");
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Add(JobApplication jobApp)
        {
            try
            {
                mJobAppRepository.Add(jobApp);
                mJobAppRepository.Save();
                return RedirectToAction("Index");
            }
            catch {
                return RedirectToAction("Error");
            }
        }
    }
}
